Function CurrentTime()
	CurrentTime = OKTime(month(now))&"/"&OKTime(day(now))&" "&OKTime(hour(now))&":"&OKTime(minute(now))&":"&OKTime(second(now))
End Function

Function OKTime(time_d)
	If time_d<10 Then
		time_d = "0"&time_d
	End If
	OKTime = time_d
End Function

Function TimeCount(start_time)
	TimeCount = (Time()-start_time)*3600*24
End Function

Function GetPath()
	Dim strPath,temppath,path_array
	strPath=environment("TestDir")
	path_array = split(strPath,"Driven")
	getpath = path_array(0)
End function

Function xls_source(xls)
	xls_source="Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="&getpath()&xls&";Extended Properties='Excel 8.0;hdr=yes'"
End Function

'Get value from external excel file
Function GetValue(preValue)
	Dim Get_DB_Statament,DB_Execute_result
	If Instr(preValue,"#") Then
		Value_Array = split(preValue,"#")
		GetValue = ADORecord(Value_Array(1)).value
		Exit function
	End If
	If instr(preValue,"^") Then
		Value_Array = split(preValue,"^")
		For i=0 to UBound(CommonIndex)
			If CommonIndex(i) = Value_Array(1) Then
				GetValue = CommonObj(i)
				Exit function
			End If
		Next
	End If
	If Instr(preValue,"Chr(34)") Then
		preValue = Replace(preValue,"Chr(34)",Chr(34))
	End If
	GetValue = preValue
End Function

Function xls_src(xls)
	xls_src="Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="&xls&";Extended Properties='Excel 8.0;hdr=yes'"
End Function

Function CreateFolders(PathString)
	Dim path_array,tag
	On error resume next
	path_array = split(PathString,"\")
	For tag = 1 to UBound(path_array)
		path_array(tag) = path_array(tag-1)&"\"&path_array(tag)
	Next
	path_array(0)=path_array(0)&"\"
	For tag=0 to UBound(path_array)
		Save_to_obj.CreateFolder(path_array(tag))
	Next
	If err.number = 0 Then
		CreateFolders = true
	Else
		CreateFolders = false
	End If
End Function


'*********************************************************************
'Last Modified By/Date:	
'This function is used to convert the string path of control  to object
'Parameter:
'	strWindow:  The window name
'  	strControlName: The object name
'Output:  
'	True: Convert the string path to object successful
'	False: Cannot convert the string path to object
'*********************************************************************
Public Function ConvertObject (strWindow, strControlName)
	On Error Resume Next
	strObjectText = ""
'	If InStr(strControlName, "=") = 0 Then
		strObjectText = SearchWindowControl (strFILEXML, strWindow, strControlName)
'	Else
'		strObjectText = SearchWindow (strFILEXML, strWindow)
'	End If
	If strObjectText <> "" And Not IsEmpty(strObjectText) Then
		Execute ("Set oControl = " & strObjectText)
'		If InStr(strControlName, "=") > 0 Then
'			Set ConvertObject = CreateDynamicControl (oControl, strControlName)
'		Else
			Set ConvertObject = oControl
'		End If	
	End If
	Set oControl = Nothing	
	If Err.Number <> 0 Then
		Set ConvertObject = Nothing	
	End If
End Function


'*********************************************************************
'Last Modified By/Date:
'This Function is used to return the path of control by reading xml
'Parameter:
'	strFILEXML: The XML file name
'	strWindow: The Window name
'	strControl: The Control name
'Output: The path of control
'*********************************************************************
Public Function SearchWindowControl (strFILEXML, strWindow, strControl)
	Dim xPath ,strNode, strPathWindow
	'Using xpath for XML, reference : http://www.w3schools.com/xpath/default.asp
	xPath = "//qtpRep:Object [@Name = '" &strWindow& "']//qtpRep:Object [@Name = '" &strControl& "']"
	Set strNode = xmlDoc.ChildElementsByPath(xPath)
	If strNode.Count() <> 0  Then
'		If CheckDirectlyControl (strControl ,SearchWindow (strFILEXML, strWindow)) Then
'			strControlTemp = Replace (WalkAttributes (strNode.Item (1)), ").", ")")
'			strPathWindow = SearchWindow (strFILEXML, strWindow)
'			SearchWindowControl = strPathWindow + "." + strControlTemp
'			Else
			GetNodePath strNode.Item (1), Replace (WalkAttributes (strNode.Item (1)), ").", ")")
			SearchWindowControl = strIsWindow
'		End If
'	Else
	End If
	blStop = false
	strIsWindow = ""
End Function


'******************************************************************
'Last Modified By/Date:
'Get current path folder.
'Parameter: None
'Output: The current path folder
'*********************************************************************
Public Function GetCurrentPath()
	strCurrentPath = Environment("TestDir")
	strFolderName = ParseString(strCurrentPath, "\")
	strCurrentPath = left(strCurrentPath, len(strCurrentPath) - len(strFolderName) - 1)				
	GetCurrentPath = strCurrentPath & "\"
End Function


'*********************************************************************
'Last Modified By/Date:
'This action is used to parse string from other string
'Parameter:
'	strText: The string
'  	strDelimiter: The delimiter to identify substring limits
'Output:  The string
'*********************************************************************
Public Function ParseString (strText, strDelimiter)
	strTextTemp = right(strText, len(strText) - InStrRev(strText, strDelimiter))
	ParseString = strTextTemp
End Function


'********************************************************************
'Last Modified By/Date:
'This Function is used to load xml file
'Parameter:
'	strFILEXML: The XML file name
'Output: None
'*********************************************************************
Public Function LoadXML(strFILEXML)
	Set xmlTempDoc = XMLUtil.CreateXML()
	xmlTempDoc.Loadfile (strFILEXML)
	Set LoadXML = xmlTempDoc
End Function


'********************************************************************
'Last Modified By/Date:
'This Function is get the path from root to control by reading XML.
'Parameter:
'	Node: The node
'	strGetNodePath: The node path
'Output: True/False
'*********************************************************************
Public Function GetNodePath (node, strGetNodePath)
	blStop = false
	strTemp = strGetNodePath
	While blStop = false
		if (node.ElementName() = "qtpRep:Objects") Then
			blStop = true
			Else  
			Set node = node.Parent ()
			strTemp = WalkAttributes (node) + strTemp   
		End If		
	Wend
	strIsWindow = strTemp   
End Function


'*********************************************************************
'Last Modified By/Date:
'This Function is used to return the type and name of node
'Parameter:
'Node: The node
'Output: The name of node
'*********************************************************************
Public Function WalkAttributes(Node)
	If IsObjectNode (node)  Then
		Dim iIndex, iTotalAttributes, Attrib, strValue, strName,strAttr
		iIndex = 1
		iTotalAttributes =Node.Attributes().Count()		
		While iIndex <= iTotalAttributes
			Set Attrib = Node.Attributes().Item(iIndex)
			strValue = Attrib.Value()
			strName = Attrib.Name()			
			If strName = "Class" Then
					strAttr = strAttr + ""+strValue+""
					Else
					strAttr = strAttr + "("+chr(34)+strValue+chr(34) + ")" 
			End If
			iIndex = iIndex + 1
		Wend
			WalkAttributes = strAttr + "."
		Exit Function
	End If
	WalkAttributes = ""
End Function


'*********************************************************************
'Last Modified By/Date:
'This Function is check node is the qtpRep:Object or not.
'Parameter:
'	Node: The node
'Output: True/False
'*********************************************************************
Public Function IsObjectNode (node)
	If node.ElementName() = "qtpRep:Object" Then
		IsObjectNode = true
	Else
		IsObjectNode = false
	End If
End Function


'*********************************************************************
'Last Modified By/date:
'Get the exist state of Object.
'Parameter:
'  	oObject: The object
'Output: 
'	True: ObjectName is existed
'	False: ObjectName is not existed
'*********************************************************************
Public Function DoesObjectExist (oObject)
	DoesObjectExist = False
	On Error Resume Next
	Err.clear
	If oObject.Exist(2) Then
		If Err.Number = 0 Then
			DoesObjectExist = True
		End If	
	End If
End Function